package com.neusoft.demo4;

public class Example {
    //已知数组{1，2，3，4，5，6}，定义一个方法求数组中所有元素的和
    public static int sum(int[] arr){
        //int[] arr = {1,2,3,4,5,6};
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum;
    }
    public static void main(String[] args) {
        int[] array = {1,2,3,4,5,6};
        int total = Example.sum(array);
        System.out.println(total);
    }
}
